package org.quickserver.net.client.monitoring.impl;

import java.io.IOException;
import java.util.Date;
import java.util.logging.Logger;
import org.quickserver.net.client.Host;
import org.quickserver.net.client.monitoring.HostMonitor;
















public class PingMonitor
  implements HostMonitor
{
  private static final Logger logger = Logger.getLogger(PingMonitor.class.getName());
  
  public char monitor(Host host) {
    try {
      boolean flag = host.getInetAddress().isReachable(host.getTimeout());
      if (flag) {
        return 'A';
      }
      return 'D';
    }
    catch (IOException e) {
      logger.fine(host + " Error: " + e);
      return 'D';
    } catch (Exception e) {
      logger.warning(host + " Error: " + e);
      e.printStackTrace();
      return 'E';
    } finally {
      host.setLastCheckedOn(new Date());
    } 
  }
}
